//
//  LCViewController.m
//  JKFuYinProject
//
//  Created by jiukuyinyue on 2017/9/14.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LCViewController.h"
#import "zhAlertView.h"
#import <zhPopupController/zhPopupController.h>
#import "AlertKuangView.h"

@interface LCViewController ()

@end

@implementation LCViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [SVProgressHUD dismiss];
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.className = [NSString stringWithFormat:@"%@",[self topViewController].class];
    if (self.className) {
        NSLog(@"(百度统计)Start = %@",self.className);
        [[BaiduMobStat defaultStat] pageviewStartWithName:self.className];
    }
}
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    if (self.className) {
        NSLog(@"(百度统计)End = %@", self.className);
        [[BaiduMobStat defaultStat] pageviewEndWithName:self.className];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationItem.hidesBackButton = YES;//隐藏系统的返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home_nav_button_back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.view.backgroundColor = RGBColor(236, 236, 236);
    
    if (self.rightTitle.length > 0) {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:_rightTitle style:UIBarButtonItemStyleDone target:self action:@selector(rightBtnAction)];
    }
}
-(void)rightBtnAction{
    
}
-(void)addHubPromptMessage:(NSString *)message
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
     hud.mode = MBProgressHUDModeText;//枚举类型不同的效果
//    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text= [NSString stringWithFormat:@"%@",message];
    [self performSelector:@selector(hiddenMBAction) withObject:nil afterDelay:1.0];

}
#pragma mark - hub的弹窗
-(void)setStringWarning:(NSString *)str
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;//枚举类型不同的效果
    hud.label.text= [NSString stringWithFormat:@"%@",str];
    [self performSelector:@selector(hiddenMBAction) withObject:nil afterDelay:1.0];
}
#pragma mark - 弹出警告框
-(void)initWithtring :(NSString *)string
{
    AlertKuangView * alert = [AlertKuangView new];
    [alert moveJingGaoKuang:string:self.view];
}
-(void)hiddenMBAction
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
///自定义窗的 是黑色，字是白色 无图片
-(void)showHud1:(NSString *)str{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
    [SVProgressHUD setInfoImage:nil];
#pragma clang diagnostic pop
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom]; //自定义窗的 是黑色，字是白色
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];
    [SVProgressHUD setFont:[UIFont systemFontOfSize:13]];
    [SVProgressHUD showInfoWithStatus:str];
    [SVProgressHUD dismissWithDelay:0.6];

}
///自定义窗的 是黑色，字是白色 弹窗-福音值币图片
- (void)showHud3WithTitle:(NSString *)title :(NSString *)str
{
    if (str == nil) {
        [self showMsg:[NSString stringWithFormat:@"%@",title] duration:3 imgName:@"弹窗-福音值币"];
    }else{
        [self showMsg:[NSString stringWithFormat:@"%@\n%@",title,str] duration:3 imgName:@"弹窗-福音值币"];
    }
}
- (void)showMsg:(NSString *)msg duration:(CGFloat)time imgName:(NSString *)imgName {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.color = [[UIColor blackColor] colorWithAlphaComponent:0.7];
    //hud.bezelView.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.7];
    //    /hud.bezelView.alpha = 1;
    // 显示模式,改成customView,即显示自定义图片(mode设置,必须写在customView赋值之前)
    hud.mode = MBProgressHUDModeCustomView;
    // 设置要显示 的自定义的图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imgName]];
    // 显示的文字,比如:加载失败...加载中...
    hud.detailsLabel.text = msg;
    hud.detailsLabel.font = FONT_15;
    hud.detailsLabel.textColor = [UIColor colorWithRed:0.92 green:0.74 blue:0.26 alpha:1.00];
    // 标志:必须为YES,才可以隐藏,  隐藏的时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    [hud hideAnimated:YES afterDelay:time];
}

-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Alert loadFail 网页加载失败弹出框
- (void)example1 {
    zhAlertView *alert = [self alertView1];
    
    self.zh_popupController = [[zhPopupController alloc] init];
    [self.zh_popupController dropAnimatedWithRotateAngle:30];
    [self.zh_popupController presentContentView:alert duration:0 springAnimated:YES];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.zh_popupController dismiss];
    });
}
- (zhAlertView *)alertView1 {
    zhAlertView *alertView = [[zhAlertView alloc] initWithTitle:@"提示"
                                                        message:@"网页加载失败，请稍后重试! "
                                                  constantWidth:290];
    return alertView;
}

- (UIViewController *)_topViewController:(UIViewController *)vc {
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [self _topViewController:[(UINavigationController *)vc topViewController]];
    } else if ([vc isKindOfClass:[UITabBarController class]]) {
        return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
    } else {
        return vc;
    }
    return nil;
}
- (UIViewController *)topViewController {
    UIViewController *resultVC;
    resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
    while (resultVC.presentedViewController) {
        resultVC = [self _topViewController:resultVC.presentedViewController];
    }
    return resultVC;
}
#pragma mark- 跳转登陆界面
-(void)gotoLogin
{
    //    if([[_UserM usercode] isEqualToString:@""]){
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AccLogin" bundle:nil];
    UIViewController *controller = [sb instantiateInitialViewController];
    [self.navigationController pushViewController:controller animated:YES];
}
//- (void)getShowVCName {
//    NSLog(@"[self topViewController] = %@", [self topViewController]);
//    //    if ([[self topViewController] isKindOfClass:[clz class]]) {
//}
@end
